---
category: String
contributors:
    - chety
created: '2020-04-19'
title: Repeat a string
updated: '2021-10-13'
---

**JavaScript version**

```js repeat.js
const repeat = (str, numberOfTimes) => str.repeat(numberOfTimes);

// Or
const repeat = (str, numberOfTimes) => Array(numberOfTimes + 1).join(str);
```

**TypeScript version**

```ts repeat.ts
const repeat = (str: string, numberOfTimes: number): string => str.repeat(numberOfTimes);

// Or
const repeat = (str: string, numberOfTimes: number): string => Array(numberOfTimes + 1).join(str);
```
